package com.fare.taluo.core.domain.crawl;

import java.sql.Date;
import java.util.List;

import javax.persistence.Column;

import com.dayatang.domain.Entity;
import com.dayatang.domain.InstanceFactory;
import com.dayatang.domain.QuerySettings;
import com.fare.taluo.base.ddd.domain.baseentity.BaseEntity2;

/**
 * 抓取统计（存储持久化数据）
 * for grabDate
 * @author gan
*/
@javax.persistence.Table(name="fdc_crawl_statistics_flightline")
@javax.persistence.Entity
public class FdcCrawlStatisticsForFlightLineEntity extends BaseEntity2<FdcCrawlStatisticsForFlightLineEntity> implements Entity{

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	
/*	@Id
	@GeneratedValue(strategy = GenerationType.AUTO)
	private Long id;*/
	
	@Column(name="create_time")
	private Date createTime;
	
	@Column(name ="from_city")
	private String fromCity;
	
	@Column(name ="from_city_name")
	private String fromCityName;
	
	@Column(name ="to_city")
	private String toCity;
	
	@Column(name ="to_city_name")
	private String toCityName;
	
	@Column(name ="grab_start_date")
	private Date grabStartDate;
	
	@Column(name ="grab_end_date")
	private Date grabEndDate;
	
	@Column(name ="grab_total_source")
	private Long grabTotalSource;
	
	
	private static FdcCrawlStatisticsEntityRepository getFdcCrawlStatisticsEntityRepository(){
		return InstanceFactory.getInstance(FdcCrawlStatisticsEntityRepository.class);
	}
	
	private static FdcCrawlStatisticsForFlightLineEntityRepository getFdcCrawlStatisticsFlightLineEntityRepository(){
		return InstanceFactory.getInstance(FdcCrawlStatisticsForFlightLineEntityRepository.class);
	}
	
	/**
	 * 执行存入数据(持久化数据)
	 * for grabFlightLine (insert)
	 */	
	public  void saveDatasForFlightLine(List<FdcCrawlStatisticsForFlightLineEntity> entityList){
		getFdcCrawlStatisticsEntityRepository().saveDatasForFlightLine(entityList);
	}
	
	
	/**
	 * for grabFlightLine (update)
	 */	
	public void updateDatasForFlightLine( List<FdcCrawlStatisticsForFlightLineEntity> updateListEntity) {
		getFdcCrawlStatisticsEntityRepository().updateDatasForFlightLine(updateListEntity);
	}
	
	/**
	 * for grabFlightLine (find entity by city's code)
	 */
	public List<FdcCrawlStatisticsForFlightLineEntity> findFlightLineEntityByCityCode(String fromCityCode,String toCityCode){
		return getFdcCrawlStatisticsFlightLineEntityRepository().findForFlightLineEntity(fromCityCode, toCityCode);
	}
	

	
	public Date getCreateTime() {
		return createTime;
	}

	public void setCreateTime(Date createTime) {
		this.createTime = createTime;
	}

	public String getFromCity() {
		return fromCity;
	}

	public void setFromCity(String fromCity) {
		this.fromCity = fromCity;
	}

	public String getFromCityName() {
		return fromCityName;
	}

	public void setFromCityName(String fromCityName) {
		this.fromCityName = fromCityName;
	}

	public String getToCity() {
		return toCity;
	}

	public void setToCity(String toCity) {
		this.toCity = toCity;
	}

	public String getToCityName() {
		return toCityName;
	}

	public void setToCityName(String toCityName) {
		this.toCityName = toCityName;
	}

	public Date getGrabStartDate() {
		return grabStartDate;
	}

	public void setGrabStartDate(Date grabStartDate) {
		this.grabStartDate = grabStartDate;
	}

	public Date getGrabEndDate() {
		return grabEndDate;
	}

	public void setGrabEndDate(Date grabEndDate) {
		this.grabEndDate = grabEndDate;
	}

	public Long getGrabTotalSource() {
		return grabTotalSource;
	}

	public void setGrabTotalSource(Long grabTotalSource) {
		this.grabTotalSource = grabTotalSource;
	}

	
	
	@Override
	public boolean isNew() {
		return getId() == null ;
	}

	@Override
	public boolean existed() {
		if (isNew()) {
			return false;
		}
		return getRepository().exists(getClass(), id);
	}

	@Override
	public boolean notExisted() {
		return ! existed();
	}

	@Override
	public boolean existed(String propertyName, Object propertyValue) {
		List<?> entities = getRepository().find(QuerySettings.create(getClass()).eq(propertyName, propertyValue)); 
		return !(entities.isEmpty());
	}

	

}
